/*
 * Copyright 2013 Robert Peszek.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fpig.util

import fpig.util.curring.AutoCurring;
import fpig.util.curring.ExplicitCurring;
import fpig.util.curring.Parameter_;
import fpig.util.curring.Parameter_PartrialApplication;

/**
 * Defines curring method and soem convenience functions
 * 
 * http://code.google.com/p/fpiglet/
 * @author Robert Peszek
 */
class CallUtil {
	static def wayOfFun = new AutoCurring()
	static Parameter_PartrialApplication _syntax = new Parameter_PartrialApplication()

	static Parameter_ _ = new Parameter_()

	static Closure toFunction(Closure c) {
		Closure cx = wayOfFun.toFunction c
		_syntax.toFunction(cx)
	}

	/**
	 * Flipped version of haskell's $
	 */
	static Closure functionApplicationFlipped = {arg, Closure c -> c(arg) }

	static Closure functionApplicationFlippedPlus = {arg, Closure c -> toFunction(c)(arg)}

	static Closure flip = {Closure c-> { x,y -> c(y,x) }  }
}
